const input = {
    bind(ele, binding, vnode) {
        const el = ele.tagName === "INPUT" ? ele : ele.querySelector("input");
        let isComposing = false;

        el.addEventListener("compositionstart", function () {
            isComposing = true;
        });

        el.addEventListener("compositionend", function () {
            isComposing = false;
        });

        el.addEventListener(
            "input",
            function (e) {
                e = e || window.event;
                if (isComposing) {
                    return;
                }

                let val = e.target.value;
                let re = /^[a-z0-9A-Z_\-#\u4e00-\u9fa5/:]*$/;
                if (!re.test(val)) {
                    e.target.value = e.target.value.replace(
                        /[^a-z0-9A-Z_\-#\u4e00-\u9fa5/:]/g,
                        ""
                    );
                }

                // 这里有一个小错误需要修复
                if (vnode.componentInstance) {
                    vnode.componentInstance.$emit("input", el.value);
                } else {
                    // 修复：应该是在 CustomEvent 的构造函数中传递 input 事件的数据
                    vnode.el.dispatchEvent(
                        new CustomEvent("input", { detail: el.value })
                    );
                }
            },
            false
        );
    },
};
